import 'package:flutter_admin/utils/utils.dart';
import 'package:quiver/strings.dart';

class UdtTbWorkreportrecord {
  String? id;
  String? productionorderno;
  String? productId;
  String? productCode; //产品编号
  String? productName; //产品名称
  String? spec; //产品规格
  String? processId;
  String? processName; //工序名称
  String? stationId;
  String? stationCode; //工位编码
  String? stationName; //工位名称
  String? teamId;
  String? teamCode; //班组编码
  String? teamName; //班组名称
  String? shiftId;
  String? shiftName; //班次名称
  String? batchno;
  num? replacenumber; // 换膜个数
  num? qualifiedquantity; // 合格数量
  num? unqualifiedquantity; // 不合格数量
  num? repairquantity; // 换模个数
  String? remark;
  String? reportworkerId;
  String? reportworkerName; //报工人名称
  String? reportDate;
  String? reportDateStart;
  String? reportDateEnd;
  String? createUid;
  String? createDate;
  String? writeUid;
  String? writeName;
  String? writeDate;
  String? workshopId;
  String? workshopName; //车间名称
  String? factoryId;
  String? factoryName; //工厂名称
  String? status; //处理状态
  num? cutting; //刀数
  String? startDate;
  String? endDate;
  String? productQty;
  String? cuttingD;
  String? remarkCate;
  String? repairStatus;
  String? routeRemark; // 工序备注
  num? planQty; // 计划数量
  String? productionType; // 生产类型
  String? isWaring; // 是否警告
  String? sprayArea; // 阴影面具

  UdtTbWorkreportrecord({
    this.id,
    this.productionorderno,
    this.productId,
    this.productCode,
    this.productName,
    this.spec,
    this.processId,
    this.processName,
    this.stationId,
    this.stationCode,
    this.stationName,
    this.teamId,
    this.teamCode,
    this.teamName,
    this.shiftId,
    this.shiftName,
    this.batchno,
    this.replacenumber,
    this.qualifiedquantity,
    this.unqualifiedquantity,
    this.repairquantity,
    this.remark,
    this.reportworkerId,
    this.reportworkerName,
    this.reportDate,
    this.reportDateStart,
    this.reportDateEnd,
    this.createUid,
    this.createDate,
    this.writeUid,
    this.writeDate,
    this.writeName,
    this.workshopId,
    this.workshopName,
    this.factoryId,
    this.factoryName,
    this.status,
    this.cutting,
    this.startDate,
    this.endDate,
    this.productQty,
    this.cuttingD,
    this.remarkCate,
    this.repairStatus,
    this.routeRemark,
    this.planQty,
    this.productionType,
    this.isWaring,
    this.sprayArea,
  });

  UdtTbWorkreportrecord copyWith({
    String? id,
    String? documentno,
    String? documentname,
    String? departmentId,
    String? departmentName,
    String? documenttypeId,
    String? documenttypeName,
    String? areaId,
    String? areaName,
    String? locationId,
    String? locationName,
    String? remark,
    String? lenddeptId,
    String? lenddeptName,
    String? lenddate,
    String? lenduserId,
    String? lenduserName,
    String? returndeptId,
    String? returndeptName,
    String? returndate,
    String? returnuserId,
    String? returnuserName,
    String? createUid,
    String? createDate,
    String? writeUid,
    String? writeDate,
  }) {
    return new UdtTbWorkreportrecord(
      id: this.id,
      productionorderno: this.productionorderno,
      productId: this.productId,
      productCode: this.productCode,
      productName: this.productName,
      spec: this.spec,
      processId: this.processId,
      processName: this.processName,
      stationId: this.stationId,
      stationCode: this.stationCode,
      stationName: this.stationName,
      teamId: this.teamId,
      teamName: this.teamName,
      shiftId: this.shiftId,
      shiftName: this.shiftName,
      batchno: this.batchno,
      replacenumber: this.replacenumber,
      qualifiedquantity: this.qualifiedquantity,
      unqualifiedquantity: this.unqualifiedquantity,
      repairquantity: this.repairquantity,
      remark: this.remark,
      reportworkerId: this.reportworkerId,
      reportworkerName: this.reportworkerName,
      reportDate: this.reportDate,
      reportDateStart: this.reportDateStart,
      reportDateEnd: this.reportDateEnd,
      createUid: createUid ?? this.createUid,
      createDate: createDate ?? this.createDate,
      writeUid: writeUid ?? this.writeUid,
      writeDate: writeDate ?? this.writeDate,
      writeName: writeName ?? this.writeName,
      workshopId: this.workshopId,
      workshopName: this.workshopName,
      factoryId: this.factoryId,
      factoryName: this.factoryName,
      status: this.status,
      cutting: this.cutting,
      productionType: this.productionType,
    );
  }

  @override
  String toString() {
    return '''UdtTbWorkreportrecord{
      id: $id,
      productionorderno: $productionorderno,
      productId: $productId,
      processId: $processId,
      stationId: $stationId,
      teamId: $teamId,
      shiftId: $shiftId,
      batchno: $batchno,
      replacenumber: $replacenumber,
      qualifiedquantity: $qualifiedquantity,
      unqualifiedquantity: $unqualifiedquantity,
      repairquantity: $repairquantity,
      remark: $remark,
      reportworkerId: $reportworkerId,
      reportworkerName: $reportworkerName,
      reportDate: $reportDate,
      createUid: $createUid,
      createDate: $createDate,
      writeUid: $writeUid,
      writeDate: $writeDate,
      workshopId: $workshopId,
      factoryId: $factoryId,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is UdtTbWorkreportrecord &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          productionorderno == other.productionorderno &&
          productId == other.productId &&
          processId == other.processId &&
          stationId == other.stationId &&
          teamId == other.teamId &&
          shiftId == other.shiftId &&
          batchno == other.batchno &&
          replacenumber == other.replacenumber &&
          qualifiedquantity == other.qualifiedquantity &&
          unqualifiedquantity == other.unqualifiedquantity &&
          repairquantity == other.repairquantity &&
          remark == other.remark &&
          reportworkerId == other.reportworkerId &&
          reportDate == other.reportDate &&
          createUid == other.createUid &&
          createDate == other.createDate &&
          writeUid == other.writeUid &&
          writeDate == other.writeDate &&
          workshopId == other.workshopId &&
          factoryId == other.factoryId);
  factory UdtTbWorkreportrecord.fromReportMap(Map<String, dynamic> map) {
    return new UdtTbWorkreportrecord(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      reportworkerId: map['reportworker_id'] != false
          ? map['reportworker_id'].toString() as String?
          : "",
      reportworkerName: map['reportworker_id_name'] != false
          ? map['reportworker_id_name'].toString() as String?
          : "",
      reportDate: map['reportdate'] != false
          ? map['reportdate'].toString() as String?
          : "",
      startDate: map['start_time'] != false
          ? map['start_time'].toString() as String?
          : "",
      endDate:
          map['end_time'] != false ? map['end_time'].toString() as String? : "",
      qualifiedquantity:
          map['qualifiedquantity'] != false ? map['qualifiedquantity'] : null,
      replacenumber:
          map['replacenumber'] != false ? map['replacenumber'] : null,
      cutting: map['cutting'] != false ? map['cutting']: null,
      unqualifiedquantity:
          map['consumednumber'] != false ? map['consumednumber'] : null,
      teamId: map['team_id_id'] != false
          ? map['team_id_id'].toString() as String?
          : "",
      teamName:
          map['team_id'] != false ? map['team_id'].toString() as String? : "",
      teamCode:
          map['team_code'] != false ? map['team_code'].toString() as String? : "",
      workshopId: map['workshop_id_id'] != false
          ? map['workshop_id_id'].toString() as String?
          : "",
      workshopName: map['workshop_id'] != false
          ? map['workshop_id'].toString() as String?
          : "",
    );
  }
  factory UdtTbWorkreportrecord.fromDetailMap(Map<String, dynamic> map) {
    return new UdtTbWorkreportrecord(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      productionorderno: map['productionorderno'] != false
          ? map['productionorderno'].toString() as String?
          : "",
      productCode: map['default_code'] != false
          ? map['default_code'].toString() as String?
          : "",
      productName: map['product_name'] != false
          ? map['product_name'].toString() as String?
          : "",
      spec: map['style'] != false ? map['style'].toString() as String? : "",
      stationName: map['station_id'] != false
          ? map['station_id'].toString() as String?
          : "",
      processName: map['process_id'] != false
          ? map['process_id'].toString() as String?
          : "",
      qualifiedquantity:
          map['qualifiedquantity'] != false ? map['qualifiedquantity'] : null,
      unqualifiedquantity: map['unqualifiedquantity'] != false
          ? map['unqualifiedquantity']
          : null,
      repairquantity:
          map['repairquantity'] != false ? map['repairquantity'] : null,
      replacenumber:
          map['repairquantity'] != false ? map['repairquantity'] : null,
      cuttingD:
          map['cutting'] != false ? map['cutting'].toString() as String? : "",
      remarkCate:
          map['remark_cate'] != false ? map['remark_cate'].toString() as String? : "",
      productQty: map['product_qty'] != false
          ? map['product_qty'].toString() as String?
          : "",
      reportworkerName: map['reportworker_id_name'] != false
          ? map['reportworker_id_name'].toString() as String?
          : "",
      reportDate: map['reportdate'] != false
          ? map['reportdate'].toString() as String?
          : "",
      remark: map['remark'] != false
        ? map['remark'].toString() as String?
        : "",
      productionType: map['production_type'] != false
          ? map['production_type'].toString() as String?
          : "",
      sprayArea: map['spray_area'] != false
          ? map['spray_area'].toString() as String?
          : "0",
    );
  }
  factory UdtTbWorkreportrecord.fromMap(Map<String, dynamic> map) {
    return new UdtTbWorkreportrecord(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      productionorderno: map['productionorderno'] != false
          ? map['productionorderno'].toString() as String?
          : "",
      productId:
          (map['product_id'] != false && map['product_id']["id"] != false)
              ? map['product_id']["id"].toString() as String?
              : "",
      productCode: (map['product_id'] != false &&
              map['product_id']["default_code"] != false)
          ? map['product_id']["default_code"].toString() as String?
          : "",
      productName:
          (map['product_id'] != false && map['product_id']["name"] != false)
              ? map['product_id']["name"].toString() as String?
              : "",
      spec: (map['product_id'] != false &&
              map['product_id']["description"] != false)
          ? map['product_id']["description"].toString() as String?
          : "",
      processId: map['process_id'] != false
          ? map['process_id'][0].toString() as String?
          : "",
      processName: map['process_id'] != false
          ? map['process_id'][1].toString() as String?
          : "",
      stationId: map['station_id'] != false
          ? map['station_id'][0].toString() as String?
          : "",
      stationName: map['station_id'] != false
          ? map['station_id'][1].toString() as String?
          : "",
      teamId: map['team_id'] != false
          ? map['team_id'][0].toString() as String?
          : "",
      teamName: map['team_id'] != false
          ? map['team_id'][1].toString() as String?
          : "",
      shiftId: map['shift_id'] != false
          ? map['shift_id'][0].toString() as String?
          : "",
      shiftName: map['shift_id'] != false
          ? map['shift_id'][1].toString() as String?
          : "",
      batchno:
          map['batchno'] != false ? map['batchno'].toString() as String? : null,
      replacenumber:
          map['replacenumber'] != false ? map['replacenumber'] : null,
      qualifiedquantity:
          map['qualifiedquantity'] != false ? map['qualifiedquantity'] : null,
      planQty:
          map['plan_qty'] != false ? map['plan_qty'] : null,
      unqualifiedquantity: map['unqualifiedquantity'] != false
          ? map['unqualifiedquantity']
          : null,
      repairquantity:
          map['repairquantity'] != false ? map['repairquantity'] : null,
      remark: map['remark'] != false ? map['remark'].toString() as String? : "",
      reportworkerId: map['reportworker_id'] != false
          ? map['reportworker_id'][0].toString() as String?
          : "",
      reportworkerName: map['reportworker_id'] != false
          ? map['reportworker_id'][1].toString() as String?
          : "",
      reportDate:
          map['reportdate'] != false ? map['reportdate'].toString() : "",
      createUid: map['create_uid'] != false
          ? map['create_uid'].toString() as String?
          : "",
      createDate: map['create_date'] != false
          ? map['create_date'].toString() as String?
          : "",
      writeUid: map['write_uid'] != false
          ? map['write_uid'][0].toString() as String?
          : "",
      writeName: map['write_uid'] != false
          ? map['write_uid'][1].toString() as String?
          : "",
      writeDate: map['write_date'] != false
          ? Utils.timeUTC(map['write_date'].toString()) as String?
          : "",
      workshopId: map['workshop_id'] != false
          ? map['workshop_id'][0].toString() as String?
          : "",
      workshopName: map['workshop_id'] != false
          ? map['workshop_id'][1].toString() as String?
          : "",
      factoryId: map['factory_id'] != false
          ? map['factory_id'][0].toString() as String?
          : "",
      factoryName: map['factory_id'] != false
          ? map['factory_id'][1].toString() as String?
          : "",
      status: map['status'] != false ? map['status'].toString() as String? : "",
      cutting: map['cutting'] != false ? num.parse(map['cutting']) : 0,
      repairStatus: map['repair_status'] != false ? map['repair_status'].toString() : '',
      isWaring: map['is_waring'] != false ? map['is_waring'].toString() : '',
    );
  }

  // addformMap(Map<String, dynamic> map) {
  //   this.remark = map["remark"];
  // }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'productionorderno': this.productionorderno,
      'productId': this.productId,
      'productName': this.productName,
      'productCode': this.productCode,
      'spec': this.spec,
      'processId': this.processId,
      'processName': this.processName,
      'stationId': this.stationId,
      'stationCode': this.stationCode,
      'stationName': this.stationName,
      'teamId': this.teamId,
      'teamCode': this.teamCode,
      'teamName': this.teamName,
      'shiftId': this.shiftId,
      'shiftName': this.shiftName,
      'batchno': this.batchno,
      'replacenumber': this.replacenumber,
      'qualifiedquantity': this.qualifiedquantity,
      'unqualifiedquantity': this.unqualifiedquantity,
      'repairquantity': this.repairquantity,
      'remark': this.remark,
      'reportworkerId': this.reportworkerId,
      'reportworkerName': this.reportworkerName,
      'reportDate': this.reportDate,
      'createUid': this.createUid,
      'createDate': this.createDate,
      'writeUid': this.writeUid,
      'writeName': this.writeName,
      'writeDate': this.writeDate,
      'workshopId': this.workshopId,
      'workshopName': this.workshopName,
      'factoryId': this.factoryId,
      'factoryName': this.factoryName,
      'status': this.status,
      'cutting': this.cutting,
      'startDate': this.startDate,
      'endDate': this.endDate,
      'cuttingD': this.cuttingD,
      'remarkCate': this.remarkCate,
      'productQty': this.productQty,
      'productionType': this.productionType,
      'sprayArea': isNotBlank(sprayArea)?num.parse(this.sprayArea!)*this.qualifiedquantity!:null,
    } as Map<String, dynamic>;
  }

  List toReportDomainList() {
    List list = [
      if (this.startDate != null && this.startDate != '')
        ['startdate', '=', this.startDate],
      if (this.endDate != null && this.endDate != '')
        ['enddate', '=', this.endDate],
      if (this.workshopId != null && this.workshopId != '')
        ['workshop_id', '=', int.parse(this.workshopId!)],
      if (this.teamId != null && this.teamId != '')
        ['team_id', '=', int.parse(this.teamId!)],
      if (this.reportworkerName != null && this.reportworkerName != '')
        ['user_name', 'like', '%${this.reportworkerName}%'],
    ];
    // if (list.length == 0) {
    //   list.add(['id', '!=', null]);
    // }
    return list;
  }

  List toQualifiedquantityDomainList() {
    List list = [
      if (this.productId != null && this.productId != '')
        ['product_id', '=', int.parse(this.productId!)],
      if (this.processId != null && this.processId != '')
        ['process_id', '=', int.parse(this.processId!)],
      if (this.productionorderno != null && this.productionorderno != '')
        ['productionorderno', '=', productionorderno],
    ];
    return list;
  }

  List toDomainList() {
    List list = [
      if (this.id != null && this.id != '') ['id', '=', this.id],
      if (this.productionorderno != null && this.productionorderno != '')
        ['productionorderno', 'like', '%${this.productionorderno}%'],
      if (this.productId != null && this.productId != '')
        ['product_id', '=', this.productId],
      if (this.processId != null && this.processId != '')
        ['process_name', '=', this.processId],
      if (this.stationId != null && this.stationId != '')
        ['station_id', '=', int.parse(this.stationId!)],
      if (this.teamId != null && this.teamId != '')
        ['team_id', '=', int.parse(this.teamId!)],
      if (this.shiftId != null && this.shiftId != '')
        ['shift_id', '=', this.shiftId],
      if (this.batchno != null && this.batchno != '')
        ['batchno', '=', this.batchno],
      if (this.replacenumber != null && this.replacenumber != '')
        ['replacenumber', '=', this.replacenumber],
      if (this.qualifiedquantity != null && this.qualifiedquantity != '')
        ['qualifiedquantity', '=', this.qualifiedquantity],
      if (this.unqualifiedquantity != null && this.unqualifiedquantity != '')
        ['unqualifiedquantity', '=', this.unqualifiedquantity],
      if (this.repairquantity != null && this.repairquantity != '')
        ['repairquantity', '=', this.repairquantity],
      if (this.remark != null && this.remark != '')
        ['remark', '=', this.remark],
      if (this.reportworkerId != null && this.reportworkerId != '')
        ['reportworker_id', '=', this.reportworkerId],
      if (this.createUid != null && this.createUid != '')
        ['create_uid', '=', this.createUid],
      if (this.createDate != null && this.createDate != '')
        ['create_date', '=', this.createDate],
      if (this.writeUid != null && this.writeUid != '')
        ['write_uid', '=', this.writeUid],
      if (this.writeDate != null && this.writeDate != '')
        ['write_date', '=', this.writeDate],
      if (this.workshopId != null && this.workshopId != '')
        ['workshop_id', '=', int.parse(this.workshopId!)],
      if (this.factoryId != null && this.factoryId != '')
        ['factory_id', '=', int.parse(this.factoryId!)],
      if (this.status != null && this.status != '')
        ['status', '=', int.parse(this.status!)],
    ];
    if (this.reportDateStart != null && this.reportDateStart != '')
      list.add(['reportdate', '>=', this.reportDateStart!]);
    if (this.reportDateEnd != null && this.reportDateEnd != '')
      list.add(['reportdate', '<=', this.reportDateEnd!]);
    if (list.length == 0) {
      list.add(['id', '!=', null]);
    }
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'productionorderno': this.productionorderno,
      'product_id': int.parse(this.productId!),
      'process_id': int.parse(this.processId!),
      'station_id': int.parse(this.stationId!),
      'team_id': int.parse(this.teamId!),
      'shift_id': int.parse(this.shiftId!),
      'batchno': this.batchno,
      'replacenumber': this.replacenumber,
      'qualifiedquantity': this.qualifiedquantity,
      'unqualifiedquantity': this.unqualifiedquantity,
      'repairquantity': this.repairquantity,
      'remark': this.remark,
      'reportworker_id': int.parse(this.reportworkerId!),
      'reportdate': this.reportDate,
      'workshop_id': this.workshopId,
      'factory_id': this.factoryId,
      'status': this.status,
      'cutting': this.cutting,
      'repair_status': this.repairStatus,
      'route_remark': this.routeRemark,
      'plan_qty': this.planQty,
    } as Map<String, dynamic>;
  }

  Map<String, dynamic> listToOdooMap(
      {UdtTbWorkreportrecord? udtTbWorkreportrecord}) {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'productionorderno': this.productionorderno,
      'product_id': int.parse(udtTbWorkreportrecord!.productId!),
      'process_id': int.parse(udtTbWorkreportrecord.processId!),
      'station_id': int.parse(udtTbWorkreportrecord.stationId!),
      'team_id': int.parse(udtTbWorkreportrecord.teamId!),
      'shift_id': int.parse(udtTbWorkreportrecord.shiftId!),
      'batchno': this.batchno,
      'replacenumber': this.replacenumber,
      'qualifiedquantity': this.qualifiedquantity,
      'unqualifiedquantity': this.unqualifiedquantity,
      'repairquantity': this.repairquantity,
      'remark': this.remark,
      'reportworker_id': int.parse(udtTbWorkreportrecord.reportworkerId!),
      'reportdate': udtTbWorkreportrecord.reportDate,
      'workshop_id': udtTbWorkreportrecord.workshopId,
      'factory_id': udtTbWorkreportrecord.factoryId,
      'status': udtTbWorkreportrecord.status,
      'cutting': this.cutting,
      'route_remark': this.routeRemark,
      'plan_qty': this.planQty,
      'production_type': this.productionType,
    } as Map<String, dynamic>;
  }

  Map<String, dynamic> listToExBanjinOdooMap(
      {UdtTbWorkreportrecord? udtTbWorkreportrecord}) {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'productionorderno': this.productionorderno,
      'product_id': this.productId,
      'process_id': int.parse(udtTbWorkreportrecord!.processId!),
      'station_id': int.parse(udtTbWorkreportrecord.stationId!),
      'team_id': int.parse(udtTbWorkreportrecord.teamId!),
      'shift_id': int.parse(udtTbWorkreportrecord.shiftId!),
      'batchno': this.batchno,
      'replacenumber': this.replacenumber,
      'qualifiedquantity': this.qualifiedquantity,
      'unqualifiedquantity': this.unqualifiedquantity,
      'repairquantity': this.repairquantity,
      'remark': this.remark,
      'reportworker_id': int.parse(udtTbWorkreportrecord.reportworkerId!),
      'reportdate': udtTbWorkreportrecord.reportDate,
      'workshop_id': udtTbWorkreportrecord.workshopId,
      'factory_id': udtTbWorkreportrecord.factoryId,
      'status': udtTbWorkreportrecord.status,
      'cutting': this.cutting,
      'route_remark': this.routeRemark,
      'plan_qty': this.planQty,
      'production_type': this.productionType,
      'spray_area': this.sprayArea,
    } as Map<String, dynamic>;
  }

//</editor-fold>

}
